<!DOCTYPE html>
<html>

<head>
    <title>Login</title>
    <style>
        .login_tb {
            background-color: bisque;
            align-content: center;
        }
    </style>
    <script src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
    <script src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/global.js"></script>
    <script type="text/javascript" src="js/login.js"></script>
    <script type="text/javascript" src="js/sha512.js"></script>
    <script type="text/javascript" src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
    <script>
        var UserIPv4;
        var UserIPv6;

        function setUserIPv6(r) {
            UserIPv6 = r["ip"];
            // alert(UserIPv6);
        }
        function setUserIPv4(r) {
            UserIPv4 = r["ip"];
            // alert(UserIPv4);
        }
        function t_login_check() {
            var status = "";
            status = sessionStorage.getItem("status");
            if (status == "ok") {
                window.location.href = "index.html";
            }
        }

        window.capCallback = function (res) {
            console.log(res)
            // res（用户主动关闭验证码）= {ret: 2, ticket: null}
            // res（验证成功） = {ret: 0, ticket: "String", randstr: "String"}
            if (res.ret === 0) {
                checkCaptcha(res);
            }
        }

        function checkCaptcha(res) {
            // alert("ok");
            var aid = "2090784984";
            var AppSecretKey = "0PUZxPDMrVHGhATkFOE4WmQ**";
            var Ticket = res.ticket;
            var Randstr = res.randstr;
            var UserIP;
            if (UserIPv6 != "") {
                UserIP = UserIPv6;
            } else {
                UserIP = UserIPv4;
            }

            $.ajax({
                type: "GET",
                url: "https://ssl.captcha.qq.com/ticket/verify",
                async: true,
                dataType: 'jsonp',
                data: {
                    aid: aid,
                    AppSecretKey: AppSecretKey,
                    Ticket: Ticket,
                    Randstr: Randstr,
                    UserIP: UserIP,
                },

                error: function (XMLHttpRequest, textStatus,
                    errorThrown) {
                    //alert("出错了，请于管理员联系");
                    login();
                },
                success: function (json) {
                    if (json.response == "1") {
                        login()
                    } else if (json.response == "0") {
                        alert("未通过验证");

                    } else if (json.response == "100") {
                        alert("AppSecretKey参数校验错误");
                    }
                }
            });
        }
    </script>

    <script src="https://ipv6.vm0.test-ipv6.com/ip/?callback=setUserIPv6"></script>
    <script src="https://ipv4.vm0.test-ipv6.com/ip/?callback=setUserIPv4"></script>
</head>

<body onload='t_login_check()'>
    <div>
        <h2 id="tx">登录</h2>
    </div>
    <form class="login_tb" action="/" method="GET">
        <table>
            <tr>
                <td>用户名</td>
                <td colspan="3">
                    <input type="text" name="un" oninput="checkUserName()" />
                </td>
            </tr>
            <tr>
                <td>密码</td>
                <td colspan="3">
                    <input type="password" name="pw" disabled="disabled" />
                </td>
            </tr>
            <tr>
                <td><button id="TencentCaptcha" data-appid="2090784984" data-cbfn="capCallback"
                            type="button">登录</button>
                </td>
                <td><input type="button" value="人脸识别" /></td>
            </tr>

        </table>



    </form>
</body>

</html>